﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UwinEducation.Domain.Entities
{
    [Table("sys_users")]
    public class User : EntityBase
    {
        public Guid Id { get; private set; }
        public string UserName { get; private set; }
        public string? RealName { get; private set; }
        public string? Email { get; private set; }
        public string? PhoneNumber { get; private set; }
        public string PasswordHash { get; private set; }
        public bool IsActive { get; private set; }
        public DateTime? LastLoginTime { get; private set; }
        //public ICollection<UserRole> UserRoles { get; private set; }

        public User() { }

        public static User Create(string userName, string realName, string phoneNumber, string email, string passwordHash)
        {
            return new User
            {
                Id = Guid.NewGuid(),
                UserName = userName,
                RealName = realName,
                PhoneNumber = phoneNumber,
                Email = email,
                PasswordHash = passwordHash,
                IsActive = true,
            };
        }


        public void Update(string userName, string realName, string phoneNumber, string email, bool isActive)
        {
            UserName = userName;
            RealName = realName;
            PhoneNumber = phoneNumber;
            Email = email;
            IsActive = isActive;
        }

        public void UpdatePassword(string newPasswordHash)
        {
            PasswordHash = newPasswordHash;
        }

        public void SetLastLoginTime(DateTime time)
        {
            LastLoginTime = time;
        }

        public void Deactivate()
        {
            IsActive = false;
        }

        public void Activate()
        {
            IsActive = true;
        }
    }
}
